using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_USERRIGHT
    {
        public void SetUpNewRow(ref DataRow dwReturn, DataRow dwInput = null)
        {
            switch (app.company)
            {
                default:
                case "YGR":
                    #region
                    dwReturn["MANDANT"] = "00";
                    dwReturn["ROWNID"] = "0";
                    dwReturn["COMPANY"] = "TST";
                    dwReturn["USERID"] = "";
                    dwReturn["PROCESS"] = "";
                    dwReturn["PROG"] = "";
                    dwReturn["CONTROLS"] = "";
                    dwReturn["REMARK"] = "";
                    dwReturn["P1"] = "";
                    dwReturn["P2"] = "";
                    dwReturn["P3"] = "";
                    dwReturn["P4"] = "";
                    dwReturn["P5"] = "";
                    dwReturn["P6"] = "";
                    dwReturn["P7"] = "";
                    dwReturn["P8"] = "";
                    dwReturn["P9"] = "";
                    dwReturn["P0"] = "";
                    dwReturn["NEWUSER"] = "";
                    dwReturn["NEWTIME"] = "";
                    dwReturn["CHGUSER"] = "";
                    dwReturn["CHGTIME"] = "";

                    #endregion
                    break;
            }
        }

        public void InsertICC_USERRIGHT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            dwData["NEWUSER"] = app.User;
            dwData["NEWTIME"] = date;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                default:
                    or1.CommandText = "INSERT INTO ICC_USERRIGHT ( MANDANT,ROWNID,COMPANY,USERID,PROCESS,PROG,CONTROLS,REMARK,P1,P2,P3,P4,P5,P6,P7,P8,P9,P0,NEWUSER,NEWTIME,CHGUSER,CHGTIME)"
                    + " VALUES (:MANDANT:,:ROWNID:,:COMPANY:,:USERID:,:PROCESS:,:PROG:,:CONTROLS:,:REMARK:,:P1:,:P2:,:P3:,:P4:,:P5:,:P6:,:P7:,:P8:,:P9:,:P0:,:NEWUSER:,:NEWTIME:,:CHGUSER:,:CHGTIME:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        }

        public DataSet QueryICC_USERRIGHT(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_USERRIGHT WHERE  ROWNUM<2 ";
                    break;
                case 3:
                    or1.CommandText = "SELECT * FROM ICC_USERRIGHT  WHERE COMPANY=:COMPANY: AND USERID=:USERID:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case -1:
                    or1.CommandText = "SELECT * FROM ICC_USERRIGHT";
                    break;
                default:
                    break;
            }
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_USERRIGHT";
            return SResult;
        }

        public void DeleteICC_USERRIGHT(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "DELETE FROM ICC_USERRIGHT ";
                    break;
                case 1:
                    or1.CommandText = "DELETE FROM ICC_USERRIGHT "
                                + " WHERE  MANDANT=:MANDANT: AND ROWNID=:ROWNID:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }

        public void UpdateICC_USERRIGHT(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            if (dwData != null)
            {
                dwData["CHGUSER"] = app.User;
                dwData["CHGTIME"] = date;
            } 
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                default:
                case 1:
                    or1.CommandText = "UPDATE ICC_USERRIGHT SET MANDANT=:MANDANT:,ROWNID=:ROWNID:,COMPANY=:COMPANY:,USERID=:USERID:,PROCESS=:PROCESS:,PROG=:PROG:,CONTROLS=:CONTROLS:,REMARK=:REMARK:,P1=:P1:,P2=:P2:,P3=:P3:,P4=:P4:,P5=:P5:,P6=:P6:,P7=:P7:,P8=:P8:,P9=:P9:,P0=:P0:,NEWUSER=:NEWUSER:,NEWTIME=:NEWTIME:,CHGUSER=:CHGUSER:,CHGTIME=:CHGTIME:"
                          + " WHERE  MANDANT=:MANDANT: AND ROWNID=:ROWNID:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
